home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
60754
/
60754.xpi
/
chrome
/
content
/
ststimer.js
< prev
next >
Wrap
Text File
|
2010-02-05
|
14KB
|
320 lines
/*
Timer based on:
*** Time Zone Count Down Javascript ***
http://rainbow.arch.scriptmania.com/scripts/timezone_countdown.html
*/
if(!ststimer) var ststimer = {};
ststimer = function() {
var today = new Date();
var launchDate = null;
var orbitInsertion = null;
var deorbitIgnition = null;
var landingDate = null;
var newCountdownDate = null;
var missionNumber = null;
var missionName = null;
var issAssemblyFlight = null;
var orbiter = null;
var nextMissionNumber = null;
var nextIssAssemblyFlight = null;
var nextOrbiter = null;
var panelOpenTime = 0;
function startTimer() {
displayTimer(setTimer(today), "sb_ststimer");
}
function setTimer(today) {
var diffDate = new Date(0);
diffDate.setMilliseconds(launchDate - today);
return Math.floor(diffDate.valueOf() / 1000);
}
function displayTimer(timer, sb_ststimer) {
var string = document.getElementById("string_bundle");
today = new Date();
var sbPanel = document.getElementById("sb_ststimer");
var panel = document.getElementById("sb_popup_panel");
var panelLabel = document.getElementById("sb_popup_panel_label");
if (timer == 9*60) {
panelLabel.value = string.getString("finalSequence");
panel.openPopup(sbPanel, "before_start", 0, 0, false);
}
if (timer == 31) {
panelLabel.value = string.getString("autoSequence");
panel.openPopup(sbPanel, "before_start", 0, 0, false);
}
if (timer == 0) {
panelLabel.value = string.getString("liftoff");
panel.openPopup(sbPanel, "before_start", 0, 0, false);
}
if (timer == -520) {
panelLabel.value = string.getString("MECO");
panel.openPopup(sbPanel, "before_start", 0, 0, false);
}
if (timer == (launchDate - orbitInsertion) / 1000) {
panelLabel.value = string.getString("orbit");
panel.openPopup(sbPanel, "before_start", 0, 0, false);
}
if (timer == (launchDate - deorbitIgnition) / 1000) {
panelLabel.value = string.getString("deorbit");
panel.openPopup(sbPanel, "before_start", 0, 0, false);
}
if (timer == (launchDate - landingDate) / 1000) {
panelLabel.value = string.getString("landing");
panel.openPopup(sbPanel, "before_start", 0, 0, false);
}
if (panel.state == "open") {
panelOpenTime += 1;
if (panelOpenTime == 10) {
panel.hidePopup();
panelOpenTime = 0;
}
}
if (timer <= 9*60) sbPanel.style.fontWeight = "bolder";
if (timer <= 31) sbPanel.style.color = "red";
if (timer <= -520) sbPanel.style.color = "";
if (timer <= (launchDate - orbitInsertion) / 1000) sbPanel.style.fontWeight = "";
if (timer <= (launchDate - deorbitIgnition) / 1000) sbPanel.style.fontWeight = "bolder";
if (timer <= (launchDate - landingDate) / 1000) sbPanel.style.fontWeight = "";
if (timer == (launchDate - newCountdownDate) / 1000) ststimer.onLoad().worker.postMessage("");
var secs = timer % 60;
var countdown1 = (timer - secs) / 60;
var mins = countdown1 % 60;
var countdown2 = (countdown1 - mins) / 60;
var hours = countdown2 % 24;
var days = (countdown2 - hours) / 24;
if (timer < 0) {
if (landingDate < today) document.getElementById(sb_ststimer).label = missionName + string.getString("missionEnd");
else {
if (ststimer.sb_mode == 0) document.getElementById(sb_ststimer).label = missionName + "+ " + Math.abs(days) + " " + (Math.abs(days) == 1 ? string.getString("day") : string.getString("days")) + " : " + (Math.abs(hours) < 10 ? "0" + Math.abs(hours) : Math.abs(hours)) + " : " + (Math.abs(mins) < 10 ? "0" + Math.abs(mins) : Math.abs(mins)) + " : " + (Math.abs(secs) < 10 ? "0" + Math.abs(secs) : Math.abs(secs));
if (ststimer.sb_mode == 1) document.getElementById(sb_ststimer).label = missionName + "+ " + Math.abs(days) + "d : " + Math.abs(hours) + "h : " + Math.abs(mins) + "m : " + Math.abs(secs) + "s";
if (ststimer.sb_mode == 2) {
if (days == 0) document.getElementById(sb_ststimer).label = missionName + "+ " + (Math.abs(hours) < 10 ? "0" + Math.abs(hours) : Math.abs(hours)) + " : " + (Math.abs(mins) < 10 ? "0" + Math.abs(mins) : Math.abs(mins)) + " : " + (Math.abs(secs) < 10 ? "0" + Math.abs(secs) : Math.abs(secs));
else document.getElementById(sb_ststimer).label = missionName + "+ " + Math.abs(days) + " " + (Math.abs(days) == 1 ? string.getString("day") : string.getString("days"));
}
if (ststimer.sb_mode == 3) document.getElementById(sb_ststimer).label = missionName + "+ " + Math.abs(days) + " " + (Math.abs(days) == 1 ? string.getString("day") : string.getString("days"));
}
}
else {
if (missionNumber != 0) {
if (ststimer.sb_mode == 0) document.getElementById(sb_ststimer).label = missionName + "- " + days + " " + (days == 1 ? string.getString("day") : string.getString("days")) + " : " + (hours < 10 ? "0" + hours : hours) + " : " + (mins < 10 ? "0" + mins : mins) + " : " + (secs < 10 ? "0" + secs : secs);
if (ststimer.sb_mode == 1) document.getElementById(sb_ststimer).label = missionName + "- " + days + "d : " + hours + "h : " + mins + "m : " + secs + "s";
if (ststimer.sb_mode == 2) {
if (days == 0) document.getElementById(sb_ststimer).label = missionName + "- " + (hours < 10 ? "0" + hours : hours) + " : " + (mins < 10 ? "0" + mins : mins) + " : " + (secs < 10 ? "0" + secs : secs);
else document.getElementById(sb_ststimer).label = missionName + "- " + days + " " + (days == 1 ? string.getString("day") : string.getString("days"));
}
if (ststimer.sb_mode == 3) document.getElementById(sb_ststimer).label = missionName + "- " + days + " " + (days == 1 ? string.getString("day") : string.getString("days"));
}
else document.getElementById(sb_ststimer).label = missionName + string.getString("stsEnd");
}
}
return {
personas : null,
isThemeSelected : null,
prefs : null,
sb_icon : null,
sb_name : null,
sb_mode : null,
onLoad : function() {
this.personas = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("lightweightThemes.");
this.personas.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.personas.addObserver("", this, false);
try {
this.isThemeSelected = this.personas.getBoolPref("isThemeSelected")
}
catch(e){
this.isThemeSelected = false
}
this.blackLabels();
this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("ststimer.");
this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.prefs.addObserver("", this, false);
this.sb_icon = this.prefs.getBoolPref("sb_icon");
this.sb_name = this.prefs.getBoolPref("sb_name");
this.sb_mode = this.prefs.getIntPref("sb_mode");
var self = this;
var worker = new Worker("chrome://ststimer/content/data.js");
worker.onmessage = function(event) {
var row = event.data.split("\n");
orbitInsertion = new Date(row[4]);
orbitInsertion.setHours(orbitInsertion.getHours() - today.getTimezoneOffset()/60);
deorbitIgnition = new Date(row[5]);
deorbitIgnition.setHours(deorbitIgnition.getHours() - today.getTimezoneOffset()/60);
landingDate = new Date(row[6]);
landingDate.setHours(landingDate.getHours() - today.getTimezoneOffset()/60);
newCountdownDate = new Date(landingDate);
newCountdownDate.setDate(newCountdownDate.getDate() + 3);
if (newCountdownDate > today) {
missionNumber = row[0];
issAssemblyFlight = row[1];
orbiter = row[2];
launchDate = new Date(row[3]);
nextMissionNumber = row[7];
nextIssAssemblyFlight = row[8];
nextOrbiter = row[9];
}
else {
missionNumber = row[7];
issAssemblyFlight = row[8];
orbiter = row[9];
launchDate = new Date(row[10]);
}
launchDate.setHours(launchDate.getHours() - today.getTimezoneOffset()/60);
self.showIcon();
self.showName();
self.changeMode();
setInterval(startTimer, 1000);
};
worker.postMessage("");
},
onUnload : function() {
if(!this.personas) return;
this.personas.removeObserver("", this);
if(!this.prefs) return;
this.prefs.removeObserver("", this);
},
observe : function(aSubject, aTopic, aData) {
if(aTopic != "nsPref:changed") return;
switch (aData) {
case "isThemeSelected" :
this.isThemeSelected = this.personas.getBoolPref("isThemeSelected");
this.blackLabels();
break;
case "sb_icon" :
this.sb_icon = this.prefs.getBoolPref("sb_icon");
this.showIcon();
break;
case "sb_name" :
this.sb_name = this.prefs.getBoolPref("sb_name");
this.showName();
break;
case "sb_mode" :
this.sb_mode = this.prefs.getIntPref("sb_mode");
this.changeMode();
break;
}
},
showIcon : function() {
if (this.sb_icon == true) {
if (missionNumber != 0) document.getElementById("sb_ststimer").src = "http://max91ao.altervista.org/ststimer/mission/" + missionNumber + ".png";
else document.getElementById("sb_ststimer").src = "http://max91ao.altervista.org/ststimer/mission/sts.png"
}
else document.getElementById("sb_ststimer").src = "";
},
showName : function() {
if (this.sb_name == true) {
if (missionNumber != 0) missionName = "<STS-" + missionNumber + "> ";
else missionName = "<STS> ";
}
else missionName = "";
if (missionNumber != null) startTimer();
},
changeMode : function() {
var centralClick_group = document.getElementById("sb_popup_centralClick_group");
if (this.sb_mode == 0) centralClick_group.selectedIndex = 0;
if (this.sb_mode == 1) centralClick_group.selectedIndex = 1;
if (this.sb_mode == 2) centralClick_group.selectedIndex = 2;
if (this.sb_mode == 3) centralClick_group.selectedIndex = 3;
if (missionNumber != null) startTimer();
},
blackLabels : function(){
if (this.isThemeSelected == true) {
document.getElementById("sb_popup_centralClick_group").style.color = "black";
document.getElementById("sb_popup_leftClick").style.color = "black";
document.getElementById("sb_popup_leftClick_stsEnd").style.color = "black";
document.getElementById("sb_popup_panel").style.color = "black";
}
else {
document.getElementById("sb_popup_centralClick_group").style.color = "";
document.getElementById("sb_popup_leftClick").style.color = "";
document.getElementById("sb_popup_leftClick_stsEnd").style.color = "";
document.getElementById("sb_popup_panel").style.color = "";
}
},
onClick : function(event) {
var sbPanel = document.getElementById("sb_ststimer");
var string = document.getElementById("string_bundle");
var leftClick = document.getElementById("sb_popup_leftClick");
var leftClick_label1 = document.getElementById("sb_popup_leftClick_label1");
var leftClick_label2 = document.getElementById("sb_popup_leftClick_label2");
var leftClick_label3 = document.getElementById("sb_popup_leftClick_label3");
var leftClick_label4 = document.getElementById("sb_popup_leftClick_label4");
if (event.button == 0) {
if (missionNumber != 0) {
if (launchDate > today) {
leftClick_label1.value = string.getString("mission") + " STS-" + missionNumber;
leftClick_label2.value = string.getString("issAssemblyFlight") + " " + issAssemblyFlight;
leftClick_label3.value = string.getString("orbiter") + " " + orbiter;
leftClick_label4.value = string.getString("launchString") + " " + launchDate.toLocaleString();
leftClick.openPopup(sbPanel, "before_start", 0, 0, false);
}
else {
if (landingDate < today) {
if (nextMissionNumber != 0) {
leftClick_label1.value = string.getString("nextMission") + " STS-" + nextMissionNumber;
leftClick_label2.value = string.getString("issAssemblyFlight") + " " + nextIssAssemblyFlight;
leftClick_label3.value = string.getString("orbiter") + " " + nextOrbiter;
leftClick_label4.value = string.getString("startCountdown") + " " + newCountdownDate.toLocaleString();
leftClick.openPopup(sbPanel, "before_start", 0, 0, false);
}
else document.getElementById("sb_popup_leftClick_stsEnd").openPopup(sbPanel, "before_start", 0, 0, false);
}
else {
leftClick_label1.value = string.getString("mission") + " STS-" + missionNumber;
leftClick_label2.value = string.getString("issAssemblyFlight") + " " + issAssemblyFlight;
leftClick_label3.value = string.getString("orbiter") + " " + orbiter;
leftClick_label4.value = string.getString("landingString") + " " + landingDate.toLocaleString();
leftClick.openPopup(sbPanel, "before_start", 0, 0, false);
}
}
}
else document.getElementById("sb_popup_leftClick_stsEnd").openPopup(sbPanel, "before_start", 0, 0, false);
}
if (event.button == 1) document.getElementById("sb_popup_centralClick").openPopup(sbPanel, "before_start", 0, 0, true);
if (event.button == 2) document.getElementById("sb_popup_rightClick").openPopup(sbPanel, "before_start", 0, 0, true);
}
};
}();
window.addEventListener("load", function(e) { ststimer.onLoad(); }, false);
window.addEventListener("unload", function(e) { ststimer.onUnload(); }, false);